!  FUNCTIONS/SUBROUTINES exported from SolDensMatrixFinalRound.dll:

subroutine mulMatrixVector(matrixSize,a,matrixCapacity,x,x_start,x_end,y)
	use BLAS95
	!DEC$ ATTRIBUTES DLLEXPORT::mulMatrixVector
	implicit none
	interface
	subroutine solver_gemv(c_matrix, c_x, c_y, n, x_offset, a_lda) bind(c)
		use iso_c_binding
		real(c_double) :: c_matrix(*)
		real(c_double) :: c_x(*)
		real(c_double) :: c_y(*)
		integer(c_int), value :: n
		integer(c_int), value :: x_offset
		integer(c_int), value :: a_lda
	end subroutine solver_gemv
	end interface
	integer, intent(in) :: matrixSize !����ߴ�
	integer, intent(in) :: matrixCapacity !�������Ķ�ά����ĳߴ�
	real(kind=8), intent(in) :: a(matrixCapacity,matrixCapacity)!�������Ķ�ά����
	real(kind=8), intent(in) :: x(:)!����������һά����
	integer, intent(in) :: x_start!������һά��������ռ�ռ����ʼindex
	integer, intent(in) :: x_end!������һά��������ռ�ռ�Ľ���index
	real(kind=8), intent(inout) :: y(matrixSize)!����ľ��������˽��

	! call gemv(a(1:matrixSize,1:matrixSize),x(x_start:x_end),y) !�ϴ���Ʒ��Ҫ����Ĳ���	 

	call solver_gemv(a, x, y, matrixSize, x_start, matrixCapacity)

end subroutine mulMatrixVector
	

SUBROUTINE getLU(matrixSize,a,IPIV)
!LU�ֽ�

	use LAPACK95

	!DEC$ ATTRIBUTES DLLEXPORT::getLU

	IMPLICIT NONE
	interface
	subroutine solver_getrf(c_matrix, n) bind(c)
		use iso_c_binding
		real(c_double) :: c_matrix(*)
		integer(c_int), value :: n
	end subroutine solver_getrf
	end interface
	integer, intent(in) :: matrixSize
	REAL(KIND=8),INTENT(INOUT)    :: a(matrixSize,matrixSize)
	INTEGER,intent(out)           :: IPIV(matrixSize)
	
	!����LAPACK�������о���LU�ֽ�, ���ֽ�������a����
	
	! INTEGER                       :: INFO
	! CALL GETRF(a,IPIV,INFO)                      
	! IF(INFO/=0) THEN
	! 	WRITE(14,'(A12,I5)') "DGETRF INFO=",INFO
	! 	STOP
	! ENDIF

	CALL solver_getrf(a,matrixSize)

END SUBROUTINE getLU


SUBROUTINE forwardBackWardSubstitute(matrixSize,a,ipiv,b)
!LU�ֽ�֮�����ǰ������

	use LAPACK95
	!DEC$ ATTRIBUTES DLLEXPORT::forwardBackWardSubstitute

	IMPLICIT NONE
	interface
	subroutine solver_getrs(c_rhs, n) bind(c)
		use iso_c_binding
		real(c_double) :: c_rhs(*)
		integer(c_int), value :: n
	end subroutine solver_getrs
	end interface
	integer, intent(in) :: matrixSize
	REAL(KIND=8),intent(in)    :: a(matrixSize,matrixSize)
	INTEGER,intent(in)          :: ipiv(matrixSize)
	REAL(KIND=8),intent(inout) ::  b(matrixSize)!�����Ҷ����������
		
	! call getrs(a,ipiv,b)

	CALL solver_getrs(b,matrixSize)

end SUBROUTINE forwardBackWardSubstitute


SUBROUTINE solveLinearEquations(matrixSize,a,b)
!������Է�����

	use LAPACK95
	!DEC$ ATTRIBUTES DLLEXPORT::solveLinearEquations

	IMPLICIT NONE
	integer, intent(in) :: matrixSize
	REAL(KIND=8),INTENT(IN)    :: a(matrixSize,matrixSize)
	REAL(KIND=8),INTENT(INOUT) ::  b(matrixSize)!�����Ҷ����������
	REAL(KIND=8) :: aCopy(matrixSize,matrixSize)
		
	aCopy = a

	call gesv(aCopy, b)

end SUBROUTINE solveLinearEquations


